package com.example.lenovo.test1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;

public class Main4Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
    }

    public class MainActivity extends AppCompatActivity {

        private TextView mtvDate;

        private ArrayList<String> mListDate = new ArrayList<String>();

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mtvDate = findViewById(R.id.tvDate);
            CalendarView calendarView = findViewById(R.id.calendarView);
            calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
                @Override
                public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
                    String strDate = "" + year + "-" + month + "-" + dayOfMonth;
                    if (mListDate.contains(strDate)) {
                        for (int index = 0; index < mListDate.size(); index++) {
                            String strItem2 = mListDate.get(index);
                            if (strItem2.equals(strDate)) {
                                mListDate.remove(index);
                                break;
                            }
                        }
                    } else {
                        mListDate.add(strDate);
                    }
                    String strValue = "";
                    for (String strItem : mListDate) {
                        strValue = " " + strItem;
                    }
                    mtvDate.setText(strValue);

                }
            });
        }
    }
}